package com.gxa.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.common.LayR;
import com.gxa.common.R;
import com.gxa.mapper.ServeMapper;
import com.gxa.param.ServeParam;
import com.gxa.param.TableParam;
import com.gxa.pojo.Empl;
import com.gxa.pojo.Serve;
import com.gxa.service.ServeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.List;

@Service

public class ServeServiceImpl implements ServeService {
    @Autowired
    private ServeMapper serveMapper;

//    @Override
//    public LayR list(TableParam param) {
//        PageHelper.startPage(param.getPageNum(), param.getPageSize());
//        List<Serve> serves = serveMapper.findAll(param);
//        // 封装pageInfo
//        PageInfo<Serve> pageInfo = new PageInfo<>(serves);
//
//
//        return new LayR(0, "success", pageInfo.getTotal(), pageInfo.getList());
//    }
    @Override
    public LayR list(ServeParam param) {
        PageHelper.startPage(param.getPageNum(), param.getPageSize());
        List<Serve> serves = serveMapper.findAll(param);
        // 封装pageInfo
        PageInfo<Serve> pageInfo = new PageInfo<>(serves);


        return new LayR(0, "success", pageInfo.getTotal(), pageInfo.getList());
    }





    @Override
    public R add(Serve serve) {
        serve.setLastServeTime(new Timestamp(System.currentTimeMillis()));
        serveMapper.save(serve);
        return new R(200, "添加成功！");
    }

    @Override
    public R delone(Integer serveId) {
        serveMapper.delone(serveId);
        return new R(200, "删除成功！");
    }

    @Override
    public R deleteAll(String[] ids) {
        serveMapper.deleteAll(ids);
        return new R(200, "删除成功！");
    }

    @Override
    public R detail(Integer id) {
        Serve serve = serveMapper.findByPk(id);
        return new R(200, "success", serve);
    }

    @Override
    public R edit(Serve serve) {
        serve.setLastServeTime(new Timestamp(System.currentTimeMillis()));
        serveMapper.edit(serve);
        return new R(200, "更新成功!");
    }

    @Override
    public R view(Serve serve) {
        serve.setLastServeTime(new Timestamp(System.currentTimeMillis()));
        serveMapper.view(serve);
        return new R(200, "查看成功!");
    }

    @Override
    public R submitAll(String[] ids) {
        serveMapper.submitAll(ids);
        return new R(200, "提交成功！");
    }

    @Override
    public R allocatePending(Serve serve) {
        serve.setLastServeTime(new Timestamp(System.currentTimeMillis()));
        serveMapper.allocatePending(serve);
        return new R(200, "分配成功!");
    }

    @Override
    public R conductStatus(Serve serve) {
        serve.setLastServeTime(new Timestamp(System.currentTimeMillis()));
        serveMapper.conductStatus(serve);
        return new R(200, "处理成功!");
    }


}
